package com.wyl.sso.util;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @Auther: wyl
 * @Date: 2021/7/5
 * @Description:
 */
@Data
@AllArgsConstructor
public class ResponseResult<T> {

    /**
     * 编码
     */
    private Integer code;

    /**
     * 描述信息
     */
    private String msg;

    /**
     * 结果
     */
    private T data;

    /**
     * 成功状态码
     */
    private static final int SUCCESS = 0;
    /**
     * 失败状态码
     */
    private static final int ERROR = -1;


    /**
     * 成功
     *
     * @param <T>
     * @return
     */
    public static <T> ResponseResult<T> success() {
        return new ResponseResult(SUCCESS, null, null);
    }

    /**
     * 成功
     *
     * @param result
     * @param <T>
     * @return
     */
    public static <T> ResponseResult<T> success(T result) {
        return new ResponseResult(SUCCESS, null, result);
    }

    /**
     * 成功
     *
     * @param message
     * @param result
     * @param <T>
     * @return
     */
    public static <T> ResponseResult<T> success(String message, T result) {
        return new ResponseResult(SUCCESS, message, result);
    }

    /**
     * 失败
     *
     * @param message
     * @param <T>
     * @return
     */
    public static <T> ResponseResult<T> error(String message) {
        return new ResponseResult(ERROR, message, null);
    }

    /**
     * 失败
     *
     * @param code
     * @param message
     * @param <T>
     * @return
     */
    public static <T> ResponseResult<T> error(Integer code, String message) {
        return new ResponseResult(code, message, null);
    }

}
